import Request from '../common/js/request'

// 权限接口
class PermissionService {
  /**
   * 根据关键字查询权限是否存在
   * @param keyword 权限名称、权限值
   * @param permissionId 权限Id
   */
  static getIsExistsByKeyword(keyword, permissionId) {
    const url = '/api-upms/permission/getIsExistsByKeyword'

    const data = {
      keyword,
      permissionId
    }

    return Request.get(url, data)
  }

  /**
   * 根据关键字查询权限列表
   * @param keyword 关键字
   * @param pageNum 当前页数
   * @param pageSize 每页条数
   */
  static getPermissionsByKeyword(keyword) {
    const url = '/api-upms/permission/getPermissionsByKeyword'

    const data = {
      keyword
    }

    return Request.get(url, data)
  }

  /**
   * 根据类型查询权限信息
   * @param permissionType 权限类型
   * @param permissionId 权限Id
   */
  static getPermissionsByType(permissionType, permissionId) {
    const url = '/api-upms/permission/getPermissionsByType'

    const data = {
      permissionType,
      permissionId
    }

    return Request.get(url, data)
  }

  /**
   * 添加权限
   * @param permission 权限表单对象
   */
  static insertPermission(permission) {
    const url = '/api-upms/permission/insertPermission'

    const data = permission

    return Request.post(url, data)
  }

  /**
   * 更新权限
   * @param permission 权限表单对象
   */
  static updatePermission(permission) {
    const url = '/api-upms/permission/updatePermission'

    const data = permission

    return Request.post(url, data)
  }

  /**
   * 删除权限
   * @param permissionIds 权限Id数组
   */
  static deletePermissions(permissionIds) {
    const url = '/api-upms/permission/deletePermissions'

    const data = {
      permissionIds: permissionIds.toString()
    }

    return Request.post(url, data)
  }
}

export default PermissionService
